package com.zxl.yjb.utils;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.OvershootInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.zxl.yjb.R;
import com.zxl.yjb.app.MyApplication;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.annotations.Nullable;

import static com.zxl.yjb.R.id.ll_display;

/**
 * Created by Administrator on 2017/5/24.
 */

public class DisplayUtil {

    /**
     * 将px值转换为dip或dp值，保证尺寸大小不变
     *
     * @param context
     * @param pxValue （DisplayMetrics类中属性density）
     * @return
     */
    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

    /**
     * 将dip或dp值转换为px值，保证尺寸大小不变
     *
     * @param context
     * @param dipValue （DisplayMetrics类中属性density）
     * @return
     */
    public static int dip2px(Context context, float dipValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }

    public static int getScreenWidth(){
        WindowManager wm = (WindowManager) MyApplication.getContext().getSystemService(Context.WINDOW_SERVICE);
        return wm.getDefaultDisplay().getWidth();
    }

    /**
     * 吐司  时间短
     *
     * @param context
     * @param message
     */
    public static void displayShortToast(Context context, String message) {
        if (context == null)
            return;
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }

    /**
     * 吐司  时间长
     *
     * @param context
     * @param message
     */
    public static void diaplayLongToast(Context context, String message) {
        if (context == null)
            return;
        Toast.makeText(context, message, Toast.LENGTH_LONG).show();
    }

    /**
     * 显示自定义吐司
     *
     * @param context
     * @param view    自定义View
     */
    public static void diaplayCustomeToast(Context context, View view) {
        if (context == null || view == null)
            return;
        Toast toast = new Toast(context);
        toast.setGravity(Gravity.BOTTOM, 0, 0);//位置
        toast.setDuration(Toast.LENGTH_SHORT);//时间
        toast.setView(view);
        toast.show();
    }


    /**
     * 弹出款显示
     *
     * @param context   上下文
     * @param title     弹出框标题
     * @param message   弹出框内容
     * @param listeners 弹出框底部点击事件
     */
    public static void diaplayDialog(Context context, String title, String message, final View.OnClickListener... listeners) {
        if (context instanceof Activity) {
            Activity mActivity = (Activity) context;

            //获得XML中显示区域的根视图
            final FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            final ScaleAnimation scaleShow = new ScaleAnimation(0f, 1f, 0f, 1f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            scaleShow.setInterpolator(new OvershootInterpolator());
            scaleShow.setDuration(300);
            View child = parent.findViewById(ll_display);
            if (child != null)
                parent.removeView(child);

            //获得弹出框布局
            final LinearLayout ll_display = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.display_view, null, false);
            parent.addView(ll_display);

            TextView tv_display_title = (TextView) ll_display.findViewById(R.id.tv_display_title);
            TextView tv_display_message = (TextView) ll_display.findViewById(R.id.tv_display_message);
            if (TextUtils.isEmpty(title))
                tv_display_title.setVisibility(View.GONE);

            tv_display_title.setText(title);
            tv_display_message.setText(message);

            TextView tv_cancel = (TextView) ll_display.findViewById(R.id.tv_cancel);
            TextView tv_ok = (TextView) ll_display.findViewById(R.id.tv_ok);
            tv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners[0] != null)
                        listeners[0].onClick(view);
                    parent.removeView(ll_display);//将布局移除
                }
            });
            tv_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners[1] != null)
                        listeners[1].onClick(view);
                    parent.removeView(ll_display);//将布局移除
                }
            });


            //在View布局完成后获得View的宽度和高度,布局完成后调用
            ll_display.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (ll_display.getWidth() > 0) {
                        ll_display.getChildAt(0).startAnimation(scaleShow);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            ll_display.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }
                }
            });
        }
    }


    /**
     * @param context
     * @param title
     * @param message
     * @param cancel    //取消按钮显示
     * @param ok        //确定按钮显示
     * @param listeners
     */
    public static void diaplayDialog(Context context, String title, String message, String cancel, String ok, final View.OnClickListener... listeners) {
        if (context instanceof Activity) {
            Activity mActivity = (Activity) context;

            //获得XML中显示区域的根视图
            final FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            final ScaleAnimation scaleShow = new ScaleAnimation(0f, 1f, 0f, 1f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            scaleShow.setInterpolator(new OvershootInterpolator());
            scaleShow.setDuration(300);
            View child = parent.findViewById(ll_display);
            if (child != null)
                parent.removeView(child);

            //获得弹出框布局
            final LinearLayout ll_display = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.display_view, null, false);
            parent.addView(ll_display);

            TextView tv_display_title = (TextView) ll_display.findViewById(R.id.tv_display_title);
            TextView tv_display_message = (TextView) ll_display.findViewById(R.id.tv_display_message);
            if (TextUtils.isEmpty(title))
                tv_display_title.setVisibility(View.GONE);

            tv_display_title.setText(title);
            tv_display_message.setText(message);

            TextView tv_cancel = (TextView) ll_display.findViewById(R.id.tv_cancel);
            TextView tv_ok = (TextView) ll_display.findViewById(R.id.tv_ok);
            tv_cancel.setText(cancel);
            tv_ok.setText(ok);
            tv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners[0] != null)
                        listeners[0].onClick(view);
                    parent.removeView(ll_display);//将布局移除
                }
            });
            tv_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners[1] != null)
                        listeners[1].onClick(view);
                    parent.removeView(ll_display);//将布局移除
                }
            });


            //在View布局完成后获得View的宽度和高度,布局完成后调用
            ll_display.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (ll_display.getWidth() > 0) {
                        ll_display.getChildAt(0).startAnimation(scaleShow);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            ll_display.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }
                }
            });
        }
    }

    /**
     * 底部单个按钮显示
     * @param context
     * @param title
     * @param message
     * @param ok        //确定按钮显示
     * @param listener
     */
    public static void diaplayDialogSingleButton(Context context, String title, String message, String ok, final View.OnClickListener listener) {
        if (context instanceof Activity) {
            Activity mActivity = (Activity) context;

            //获得XML中显示区域的根视图
            final FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            final ScaleAnimation scaleShow = new ScaleAnimation(0f, 1f, 0f, 1f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            scaleShow.setInterpolator(new OvershootInterpolator());
            scaleShow.setDuration(300);
            View child = parent.findViewById(ll_display);
            if (child != null)
                parent.removeView(child);

            //获得弹出框布局
            final LinearLayout ll_display = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.display_view_singlebutton, null, false);
            parent.addView(ll_display);

            TextView tv_display_title = (TextView) ll_display.findViewById(R.id.tv_display_title);
            TextView tv_display_message = (TextView) ll_display.findViewById(R.id.tv_display_message);
            LinearLayout ll= (LinearLayout) ll_display.findViewById(R.id.ll_display);

            ll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    parent.removeView(ll_display);//将布局移除
                }
            });
            if (TextUtils.isEmpty(title))
                tv_display_title.setVisibility(View.GONE);

            tv_display_title.setText(title);
            tv_display_message.setText(message);

            TextView tv_ok = (TextView) ll_display.findViewById(R.id.tv_ok);
            tv_ok.setText(ok);
            tv_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listener != null)
                        listener.onClick(view);
                    parent.removeView(ll_display);//将布局移除
                }
            });


            //在View布局完成后获得View的宽度和高度,布局完成后调用
            ll_display.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (ll_display.getWidth() > 0) {
                        ll_display.getChildAt(0).startAnimation(scaleShow);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            ll_display.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }
                }
            });
        }
    }

    /**
     * 打开相册
     * @param activity
     * @param num 最大选择数量
     * @param list 返回图片路径集合
     * @param chooseRequest 请求码
     */
    public static void openAlbum(Activity activity, int num, List<LocalMedia> list,int chooseRequest) {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofImage())// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
                .theme(R.style.picture_default_style)// 主题样式设置 具体参考 values/styles   用法：R.style.picture.white.style
                .maxSelectNum(num)// 最大图片选择数量
                .minSelectNum(1)// 最小选择数量
                .imageSpanCount(4)// 每行显示个数
                .selectionMode(num>1? PictureConfig.MULTIPLE:PictureConfig.SINGLE )// 多选 or 单选
//                        .previewImage(true)// 是否可预览图片
//                        .previewVideo(true)// 是否可预览视频
//                        .enablePreviewAudio(true) // 是否可播放音频
                .isCamera(true)// 是否显示拍照按钮
                .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
                //.imageFormat(PictureMimeType.PNG)// 拍照保存图片格式后缀,默认jpeg
                //.setOutputCameraPath("/CustomPath")// 自定义拍照保存路径
                .enableCrop(false)// 是否裁剪
                .compress(true)// 是否压缩
                .synOrAsy(false)//同步true或异步false 压缩 默认同步
                //.compressSavePath(getPath())//压缩图片保存地址
                //.sizeMultiplier(0.5f)// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效
                .glideOverride(160, 160)// glide 加载宽高，越小图片列表越流畅，但会影响列表图片浏览的清晰度
//                        .withAspectRatio(aspect_ratio_x, aspect_ratio_y)// 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
//                        .hideBottomControls(cb_hide.isChecked() ? false : true)// 是否显示uCrop工具栏，默认不显示
//                        .isGif(cb_isGif.isChecked())// 是否显示gif图片
//                        .freeStyleCropEnabled(true)// 裁剪框是否可拖拽
//                        .circleDimmedLayer(cb_crop_circular.isChecked())// 是否圆形裁剪
//                        .showCropFrame(cb_showCropFrame.isChecked())// 是否显示裁剪矩形边框 圆形裁剪时建议设为false
//                        .showCropGrid(cb_showCropGrid.isChecked())// 是否显示裁剪矩形网格 圆形裁剪时建议设为false
//                        .openClickSound(cb_voice.isChecked())// 是否开启点击声音
                .selectionMedia(list)// 是否传入已选图片
                //.isDragFrame(false)// 是否可拖动裁剪框(固定)
//                        .videoMaxSecond(15)
//                        .videoMinSecond(10)
                //.previewEggs(false)// 预览图片时 是否增强左右滑动图片体验(图片滑动一半即可看到上一张是否选中)
                //.cropCompressQuality(90)// 裁剪压缩质量 默认100
                .minimumCompressSize(256)// 小于100kb的图片不压缩
                //.cropWH()// 裁剪宽高比，设置如果大于图片本身宽高则无效
                //.rotateEnabled(true) // 裁剪是否可旋转图片
                //.scaleEnabled(true)// 裁剪是否可放大缩小图片
                //.videoQuality()// 视频录制质量 0 or 1
                //.videoSecond()//显示多少秒以内的视频or音频也可适用
                //.recordVideoSecond()//录制视频秒数 默认60s
                .forResult(chooseRequest);//结果回调onActivityResult code
    }


    /**
     * 弹出款显示
     *
     * @param context   上下文
     * @param title     弹出框标题
     * @param listeners 弹出框底部点击事件
     */
    public static void diaplayDialog(Context context, String title, String[] arr, final TextView tv_select, @Nullable final View.OnClickListener... listeners) {
        if (context instanceof Activity) {
            Activity mActivity = (Activity) context;

            //获得XML中显示区域的根视图
            final FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            final ScaleAnimation scaleShow = new ScaleAnimation(0f, 1f, 0f, 1f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            scaleShow.setInterpolator(new OvershootInterpolator());
            scaleShow.setDuration(300);
            View child = parent.findViewById(R.id.ll_select_identity);
            if (child != null)
                parent.removeView(child);

            //获得弹出框布局
            final LinearLayout ll_display = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.radio_btn_select, null, false);
            LinearLayout ll_select_join_info = (LinearLayout) ll_display.findViewById(R.id.ll_select_join_info);//单选弹出框布局

            final List<ImageView> iv_radio_imgs = new ArrayList<>();  //存储单选款的img  用于点击时转换
            final String[] selectInfo = {arr[0]};
            for (int i = 0; i < arr.length; i++) {  //根据数据数 添加弹出单选款的数量
                LinearLayout ll_radio_btn_info = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.radio_btn_show_info, null, false);
                ImageView iv_radio_img = (ImageView) ll_radio_btn_info.findViewById(R.id.iv_radio_img);
                iv_radio_imgs.add(iv_radio_img);
                TextView tv_radio_message = (TextView) ll_radio_btn_info.findViewById(R.id.tv_radio_message);
                tv_radio_message.setText(arr[i]);
                if (i == 0)
                    iv_radio_img.setImageResource(R.mipmap.login_f_pressed);  //默认第一个处于选中状态
                else
                    iv_radio_img.setImageResource(R.mipmap.login_f_normal);
                if (i == arr.length - 1) {
                    View view = ll_radio_btn_info.findViewById(R.id.view_line);
                    view.setVisibility(View.GONE);
                }
                ll_radio_btn_info.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        ImageView iv_radio_img1 = (ImageView) view.findViewById(R.id.iv_radio_img);
                        TextView tv_radio_message = (TextView) view.findViewById(R.id.tv_radio_message);
                        selectInfo[0] = tv_radio_message.getText().toString();
                        for (ImageView iv_radio_img : iv_radio_imgs) {
                            if (iv_radio_img.equals(iv_radio_img1))
                                iv_radio_img1.setImageResource(R.mipmap.login_f_pressed);
                            else
                                iv_radio_img.setImageResource(R.mipmap.login_f_normal);
                        }
                    }
                });
                ll_select_join_info.addView(ll_radio_btn_info);
            }
            parent.addView(ll_display);

            TextView tv_display_title = (TextView) ll_display.findViewById(R.id.tv_display_title);

            if (TextUtils.isEmpty(title))
                tv_display_title.setVisibility(View.GONE);
            tv_display_title.setText(title);

            TextView tv_cancel = (TextView) ll_display.findViewById(R.id.tv_cancel);
            TextView tv_ok = (TextView) ll_display.findViewById(R.id.tv_ok);
            tv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    parent.removeView(ll_display);//将布局移除
                }
            });
            tv_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    /*if (tv_select != null) {
                        tv_select.setText(selectInfo[0]);
                    }*/
                    if (listeners != null) {
                        view.setTag(selectInfo[0]);
                        listeners[0].onClick(view);
                    }
                    parent.removeView(ll_display);//将布局移除
                }
            });


            //在View布局完成后获得View的宽度和高度,布局完成后调用
            ll_display.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (ll_display.getWidth() > 0) {
                        ll_display.getChildAt(0).startAnimation(scaleShow);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            ll_display.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }
                }
            });
        }
    }


    /**
     * 弹出款显示
     *
     * @param context   上下文
     * @param title     弹出框标题
     * @param listeners 弹出框底部点击事件
     */
    public static void diaplayDialogMydata(Context context, String title, String[] arr, final TextView tv_select, @Nullable final View.OnClickListener... listeners) {
        if (context instanceof Activity) {
            Activity mActivity = (Activity) context;

            //获得XML中显示区域的根视图
            final FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            final ScaleAnimation scaleShow = new ScaleAnimation(0f, 1f, 0f, 1f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            scaleShow.setInterpolator(new OvershootInterpolator());
            scaleShow.setDuration(300);
            View child = parent.findViewById(R.id.ll_select_identity);
            if (child != null)
                parent.removeView(child);

            //获得弹出框布局
            final LinearLayout ll_display = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.radio_btn_select, null, false);
            LinearLayout ll_select_join_info = (LinearLayout) ll_display.findViewById(R.id.ll_select_join_info);//单选弹出框布局

            final List<ImageView> iv_radio_imgs = new ArrayList<>();  //存储单选款的img  用于点击时转换
            final String[] selectInfo = {arr[0]};
            for (int i = 0; i < arr.length; i++) {  //根据数据数 添加弹出单选款的数量
                LinearLayout ll_radio_btn_info = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.radio_btn_show_info, null, false);
                ImageView iv_radio_img = (ImageView) ll_radio_btn_info.findViewById(R.id.iv_radio_img);
                iv_radio_imgs.add(iv_radio_img);
                TextView tv_radio_message = (TextView) ll_radio_btn_info.findViewById(R.id.tv_radio_message);
                tv_radio_message.setText(arr[i]);
                if (tv_select.getText().toString().equals(arr[i]))
                {
                    iv_radio_img.setImageResource(R.mipmap.login_f_pressed);
                    selectInfo[0] = tv_radio_message.getText().toString();
                }
                else
                {
                    iv_radio_img.setImageResource(R.mipmap.login_f_normal);
                }

                if (i == arr.length - 1) {
                    View view = ll_radio_btn_info.findViewById(R.id.view_line);
                    view.setVisibility(View.GONE);
                }
                ll_radio_btn_info.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        ImageView iv_radio_img1 = (ImageView) view.findViewById(R.id.iv_radio_img);
                        TextView tv_radio_message = (TextView) view.findViewById(R.id.tv_radio_message);
                        selectInfo[0] = tv_radio_message.getText().toString();
                        for (ImageView iv_radio_img : iv_radio_imgs) {
                            if (iv_radio_img.equals(iv_radio_img1))
                                iv_radio_img1.setImageResource(R.mipmap.login_f_pressed);
                            else
                                iv_radio_img.setImageResource(R.mipmap.login_f_normal);
                        }
                    }
                });
                ll_select_join_info.addView(ll_radio_btn_info);
            }
            parent.addView(ll_display);

            TextView tv_display_title = (TextView) ll_display.findViewById(R.id.tv_display_title);

            if (TextUtils.isEmpty(title))
                tv_display_title.setVisibility(View.GONE);
            tv_display_title.setText(title);

            TextView tv_cancel = (TextView) ll_display.findViewById(R.id.tv_cancel);
            TextView tv_ok = (TextView) ll_display.findViewById(R.id.tv_ok);
            tv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    parent.removeView(ll_display);//将布局移除
                }
            });
            tv_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (tv_select != null) {
                        tv_select.setText(selectInfo[0]);
                    }
                    if (listeners != null) {
                        view.setTag(selectInfo[0]);
                        listeners[0].onClick(view);
                    }
                    parent.removeView(ll_display);//将布局移除
                }
            });


            //在View布局完成后获得View的宽度和高度,布局完成后调用
            ll_display.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (ll_display.getWidth() > 0) {
                        ll_display.getChildAt(0).startAnimation(scaleShow);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            ll_display.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }
                }
            });
        }
    }


    /**
     * 首页推荐商会显示
     *
     * @param context
     * @param title
     * @param listView
     * @param tv_left
     * @param tv_right
     * @param listeners
     */
    public static void diaplayDialog(Context context, String title, View listView, String tv_left, String tv_right, final View.OnClickListener... listeners) {
        if (context instanceof Activity) {
            Activity mActivity = (Activity) context;

            //获得XML中显示区域的根视图
            final FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            final ScaleAnimation scaleShow = new ScaleAnimation(0f, 1f, 0f, 1f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            scaleShow.setInterpolator(new OvershootInterpolator());
            scaleShow.setDuration(300);
            View child = parent.findViewById(R.id.ll_select_identity);
            if (child != null)
                parent.removeView(child);

            if (listView == null) {
                return;
            }

            //获得弹出框布局
            final LinearLayout ll_display = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.radio_btn_select, null, false);
            LinearLayout ll_select_join_info = (LinearLayout) ll_display.findViewById(R.id.ll_select_join_info);//单选弹出框布局

            ll_select_join_info.addView(listView);

            parent.addView(ll_display);

            TextView tv_display_title = (TextView) ll_display.findViewById(R.id.tv_display_title);

            if (TextUtils.isEmpty(title))
                tv_display_title.setVisibility(View.GONE);
            tv_display_title.setText(title);

            TextView tv_cancel = (TextView) ll_display.findViewById(R.id.tv_cancel);
            TextView tv_ok = (TextView) ll_display.findViewById(R.id.tv_ok);
            tv_cancel.setText(tv_left);
            tv_ok.setText(tv_right);

            tv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    parent.removeView(ll_display);//将布局移除
                }
            });
            tv_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    listeners[0].onClick(view);
//                    parent.removeView(ll_display);//将布局移除
                }
            });


            //在View布局完成后获得View的宽度和高度,布局完成后调用
            ll_display.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (ll_display.getWidth() > 0) {
                        ll_display.getChildAt(0).startAnimation(scaleShow);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            ll_display.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }
                }
            });
        }
    }

    /**
     * @param context
     * @param title
     * @param view
     * @param cancel    //取消按钮显示
     * @param ok        //确定按钮显示
     * @param listeners
     */
    public static void diaplayDialog(Context context, String title, String message, View view, String cancel, String ok, final View.OnClickListener... listeners) {
        if (context instanceof Activity) {
            Activity mActivity = (Activity) context;

            //获得XML中显示区域的根视图
            final FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            final ScaleAnimation scaleShow = new ScaleAnimation(0f, 1f, 0f, 1f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            scaleShow.setInterpolator(new OvershootInterpolator());
            scaleShow.setDuration(300);
            View child = parent.findViewById(ll_display);
            if (child != null)
                parent.removeView(child);

            //获得弹出框布局
            final LinearLayout ll_display = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.display_edit_txt, null, false);
            LinearLayout ll_content = (LinearLayout) ll_display.findViewById(R.id.ll_content);
            LinearLayout ll_parent = (LinearLayout) view.getParent();
            if (ll_parent != null)
                ll_parent.removeAllViews();
            ll_content.addView(view);
            parent.addView(ll_display);

            TextView tv_display_title = (TextView) ll_display.findViewById(R.id.tv_display_title);
            if (TextUtils.isEmpty(title))
                tv_display_title.setVisibility(View.GONE);

            tv_display_title.setText(title);

            TextView tv_cancel = (TextView) ll_display.findViewById(R.id.tv_cancel);
            TextView tv_ok = (TextView) ll_display.findViewById(R.id.tv_ok);
            tv_cancel.setText(cancel);
            tv_ok.setText(ok);
            tv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners[0] != null)
                        listeners[0].onClick(view);
                    parent.removeView(ll_display);//将布局移除
                }
            });
            tv_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners[1] != null)
                        listeners[1].onClick(view);
                    parent.removeView(ll_display);//将布局移除
                }
            });


            //在View布局完成后获得View的宽度和高度,布局完成后调用
            ll_display.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (ll_display.getWidth() > 0) {
                        ll_display.getChildAt(0).startAnimation(scaleShow);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            ll_display.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }
                }
            });
        }
    }


    /**
     * @param context
     * //首页 点击更多
     */
    public static void diaplayDialog(Context context, View view, final View.OnClickListener... listeners) {
        if (context instanceof Activity) {
            Activity mActivity = (Activity) context;

            //获得XML中显示区域的根视图
            final FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            final ScaleAnimation scaleShow = new ScaleAnimation(0f, 1f, 0f, 1f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            scaleShow.setInterpolator(new OvershootInterpolator());
            scaleShow.setDuration(300);
            View child = parent.findViewById(R.id.ll_display);
            if (child != null)
                parent.removeView(child);

            //获得弹出框布局
            final LinearLayout ll_display = (LinearLayout) view;
            parent.addView(ll_display);

            TextView tv_transmit= (TextView) ll_display.findViewById(R.id.tv_transmit);
            TextView tv_ignore= (TextView) ll_display.findViewById(R.id.tv_ignore);
            TextView tv_delete= (TextView) ll_display.findViewById(R.id.tv_delete);

            LinearLayout ll_wx= (LinearLayout) ll_display.findViewById(R.id.ll_wx);
            LinearLayout ll_pyq= (LinearLayout) ll_display.findViewById(R.id.ll_pyq);
            LinearLayout ll_qq= (LinearLayout) ll_display.findViewById(R.id.ll_qq);


            LinearLayout ll= (LinearLayout) ll_display.findViewById(R.id.ll_display);

            tv_transmit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners[0] != null)
                        listeners[0].onClick(view);
                    parent.removeView(ll_display);//将布局移除
                }
            });

            tv_ignore.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners[1] != null)
                        listeners[1].onClick(view);
                    parent.removeView(ll_display);//将布局移除
                }
            });

            tv_delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners[2] != null)
                        listeners[2].onClick(view);
                    parent.removeView(ll_display);//将布局移除
                }
            });

            ll_wx.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners[3] != null)
                        listeners[3].onClick(view);
                    parent.removeView(ll_display);//将布局移除
                }
            });

            ll_pyq.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners[4] != null)
                        listeners[4].onClick(view);
                    parent.removeView(ll_display);//将布局移除
                }
            });

            ll_qq.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners[5] != null)
                        listeners[5].onClick(view);
                    parent.removeView(ll_display);//将布局移除
                }
            });

            ll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    parent.removeView(ll_display);//将布局移除
                }
            });


            //在View布局完成后获得View的宽度和高度,布局完成后调用
            ll_display.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (ll_display.getWidth() > 0) {
                        ll_display.getChildAt(0).startAnimation(scaleShow);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            ll_display.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }
                }
            });
        }
    }



    /**
     * 自定义View dialog
     * @param context
     * @param title
     * @param view
     */
    public static void diaplayDialogWithView(Context context, String title, String message, View view, final View.OnClickListener... listeners) {
        if (context instanceof Activity) {
            Activity mActivity = (Activity) context;

            //获得XML中显示区域的根视图
            final FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            final ScaleAnimation scaleShow = new ScaleAnimation(0f, 1f, 0f, 1f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            scaleShow.setInterpolator(new OvershootInterpolator());
            scaleShow.setDuration(300);
            View child = parent.findViewById(R.id.ll_select_identity);
            if (child != null)
                parent.removeView(child);

            //获得弹出框布局
            final LinearLayout ll_display = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.display_dialog_with_view, null, false);
            LinearLayout ll_select_join_info = (LinearLayout) ll_display.findViewById(R.id.ll_select_join_info);//单选弹出框布局
            LinearLayout ll_parent = (LinearLayout) view.getParent();
            if (ll_parent != null)
                ll_parent.removeAllViews();
            ll_select_join_info.addView(view);
            parent.addView(ll_display);

            TextView tv_display_title = (TextView) ll_display.findViewById(R.id.tv_display_title);
            TextView tv_message = (TextView) ll_display.findViewById(R.id.tv_message);

            if (TextUtils.isEmpty(title))
                tv_display_title.setVisibility(View.GONE);
            tv_display_title.setText(title);
            if (TextUtils.isEmpty(message))
                tv_message.setVisibility(View.GONE);
                else tv_message.setText(message);

            TextView tv_cancel = (TextView) ll_display.findViewById(R.id.tv_cancel);
            TextView tv_ok = (TextView) ll_display.findViewById(R.id.tv_ok);
            tv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    parent.removeView(ll_display);//将布局移除
                }
            });
            tv_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners != null) {
                        listeners[0].onClick(view);
                    }
                    parent.removeView(ll_display);//将布局移除
                }
            });


            //在View布局完成后获得View的宽度和高度,布局完成后调用
            ll_display.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (ll_display.getWidth() > 0) {
                        ll_display.getChildAt(0).startAnimation(scaleShow);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            ll_display.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }
                }
            });
        }
    }

    /**
     * 自定义View dialog
     * @param context
     * @param title
     * @param view
     */
    public static void diaplayDialogWithView(Context context, String title, String message, String ok,String cancel, View view, final View.OnClickListener... listeners) {
        if (context instanceof Activity) {
            Activity mActivity = (Activity) context;

            //获得XML中显示区域的根视图
            final FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            final ScaleAnimation scaleShow = new ScaleAnimation(0f, 1f, 0f, 1f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            scaleShow.setInterpolator(new OvershootInterpolator());
            scaleShow.setDuration(300);
            View child = parent.findViewById(R.id.ll_select_identity);
            if (child != null)
                parent.removeView(child);

            //获得弹出框布局
            final LinearLayout ll_display = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.display_dialog_with_view, null, false);
            LinearLayout ll_select_join_info = (LinearLayout) ll_display.findViewById(R.id.ll_select_join_info);//单选弹出框布局
            LinearLayout ll_parent = (LinearLayout) view.getParent();
            if (ll_parent != null)
                ll_parent.removeAllViews();
            ll_select_join_info.addView(view);
            parent.addView(ll_display);

            TextView tv_display_title = (TextView) ll_display.findViewById(R.id.tv_display_title);
            TextView tv_message = (TextView) ll_display.findViewById(R.id.tv_message);

            if (TextUtils.isEmpty(title))
                tv_display_title.setVisibility(View.GONE);
            tv_display_title.setText(title);
            if (TextUtils.isEmpty(message))
                tv_message.setVisibility(View.GONE);
                else tv_message.setText(message);

            TextView tv_cancel = (TextView) ll_display.findViewById(R.id.tv_cancel);
            TextView tv_ok = (TextView) ll_display.findViewById(R.id.tv_ok);
            tv_cancel.setText(cancel);
            tv_ok.setText(ok);
            tv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    parent.removeView(ll_display);//将布局移除
                }
            });
            tv_ok.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listeners != null) {
                        listeners[0].onClick(view);
                    }
                    parent.removeView(ll_display);//将布局移除
                }
            });


            //在View布局完成后获得View的宽度和高度,布局完成后调用
            ll_display.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (ll_display.getWidth() > 0) {
                        ll_display.getChildAt(0).startAnimation(scaleShow);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            ll_display.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }
                }
            });
        }
    }

    /**
     * 强制更新
     * @param context
     * @param title
     * @param view
     */
    public static void diaplayForceDialog(Context context, String title, String message, View view) {
        if (context instanceof Activity) {
            Activity mActivity = (Activity) context;

            //获得XML中显示区域的根视图
            final FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            final ScaleAnimation scaleShow = new ScaleAnimation(0f, 1f, 0f, 1f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            scaleShow.setInterpolator(new OvershootInterpolator());
            scaleShow.setDuration(300);
            View child = parent.findViewById(ll_display);
            if (child != null)
                parent.removeView(child);

            //获得弹出框布局
            final LinearLayout ll_display = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.display_dialog_force, null, false);
            LinearLayout ll_content = (LinearLayout) ll_display.findViewById(R.id.ll_content);
            LinearLayout ll_parent = (LinearLayout) view.getParent();
            if (ll_parent != null)
                ll_parent.removeAllViews();
            ll_content.addView(view);
            parent.addView(ll_display);

            TextView tv_display_title = (TextView) ll_display.findViewById(R.id.tv_display_title);
            if (TextUtils.isEmpty(title))
                tv_display_title.setVisibility(View.GONE);
            tv_display_title.setText(title);
            //在View布局完成后获得View的宽度和高度,布局完成后调用
            ll_display.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (ll_display.getWidth() > 0) {
                        ll_display.getChildAt(0).startAnimation(scaleShow);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            ll_display.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }
                }
            });
        }
    }


    /**
     * @param context
     * 完全自定义布局的弹出框
     */
    public static void diaplayDialog(Context context, View view) {
        if (context instanceof Activity) {
            Activity mActivity = (Activity) context;

            //获得XML中显示区域的根视图
            final FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            final ScaleAnimation scaleShow = new ScaleAnimation(0f, 1f, 0f, 1f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            scaleShow.setInterpolator(new OvershootInterpolator());
            scaleShow.setDuration(300);
            View child = parent.findViewById(ll_display);
            if (child != null)
                parent.removeView(child);

            //获得弹出框布局
            final LinearLayout ll_display = (LinearLayout) view;
            parent.addView(ll_display);

            LinearLayout ll= (LinearLayout) ll_display.findViewById(R.id.ll_display);

            ll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    parent.removeView(ll_display);//将布局移除
                }
            });


            //在View布局完成后获得View的宽度和高度,布局完成后调用
            ll_display.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (ll_display.getWidth() > 0) {
                        ll_display.getChildAt(0).startAnimation(scaleShow);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            ll_display.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }
                }
            });
        }
    }



    //加载动画
   /* private static int[][] loadingAnimRess = new int[][]{
            new int[]{R.mipmap.loading_apple_01, R.mipmap.loading_apple_02, R.mipmap.loading_apple_03, R.mipmap.loading_apple_04,
                    R.mipmap.loading_apple_05, R.mipmap.loading_apple_06, R.mipmap.loading_apple_07, R.mipmap.loading_apple_08},
            new int[]{R.mipmap.loading_pear_01, R.mipmap.loading_pear_02, R.mipmap.loading_pear_03, R.mipmap.loading_pear_04,
                    R.mipmap.loading_pear_05, R.mipmap.loading_pear_06, R.mipmap.loading_pear_07, R.mipmap.loading_pear_08},
            new int[]{R.mipmap.loading_banana_01, R.mipmap.loading_banana_02, R.mipmap.loading_banana_03, R.mipmap.loading_banana_04,
                    R.mipmap.loading_banana_05, R.mipmap.loading_banana_06, R.mipmap.loading_banana_07, R.mipmap.loading_banana_08}
    };*/

    /**
     * x显示加载动画
     *
     * @param context 上下文  只传Activity和Fragment
     */
    public static void displayLoading(Object context) {
        if (context == null)
            return;
        try {
            Activity mActivity = null;
            if (context instanceof Activity)
                mActivity = (Activity) context;
            if (context instanceof Fragment)
                mActivity = ((Fragment) context).getActivity();
            if (mActivity == null)
                return;
            FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            String tagName = context.getClass().getSimpleName();
            View child = parent.findViewById(R.id.loading);
            if (child == null) {
                LinearLayout ll_loading_parent = new LinearLayout(mActivity);
                ll_loading_parent.setGravity(Gravity.CENTER);
                ll_loading_parent.setTag(R.id.loading, tagName);
                ll_loading_parent.setId(R.id.loading);
                ll_loading_parent.setClickable(true);//获得焦点

                LinearLayout ll_loading_view = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.display_loading, null, false);
                ImageView iv_loading = (ImageView) ll_loading_view.findViewById(R.id.iv_loading);
                ll_loading_parent.addView(ll_loading_view);
                parent.addView(ll_loading_parent);

                /**
                 * 选择动画
                 */
                RotateAnimation rotateAnimation = new RotateAnimation(0f, 360f, RotateAnimation.RELATIVE_TO_SELF, 0.5f,
                        RotateAnimation.RELATIVE_TO_SELF, 0.5f);
//                rotateAnimation.setInterpolator(new LinearInterpolator());
                rotateAnimation.setRepeatCount(-1);
                rotateAnimation.setFillAfter(true);
                rotateAnimation.setDuration(1000L);
                iv_loading.startAnimation(rotateAnimation);

                //动画显示图片下标
//                int randomIndex=(int)(Math.random()*loadingAnimRess.length);

                //启动场景动画
//                SceneAnimation sceneAnimation=new SceneAnimation(iv_loading,loadingAnimRess[randomIndex],30);

            } else {
                child.setTag(R.id.loading, tagName);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 隐藏加载动画
     *
     * @param context 只传Activity和Fragment
     */
    public static void hideLoading(Object context) {
        if (context == null)
            return;
        try {
            Activity mActivity = null;
            if (context instanceof Activity)
                mActivity = (Activity) context;
            if (context instanceof Fragment)
                mActivity = ((Fragment) context).getActivity();
            if (mActivity == null)
                return;
            FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            View child = parent.findViewById(R.id.loading);
            if (child != null) {
                String tagName = (String) child.getTag(R.id.loading);
                if (tagName.equals(context.getClass().getSimpleName()))//只有当前开启动画的界面才能关闭界面
                    parent.removeView(child);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }






     /** 显示扫描动画 */
    public static void displayScaning(Object context) {
        if (context == null)
            return;
        try {
            Activity mActivity = null;
            if (context instanceof Activity)
                mActivity = (Activity) context;
            if (context instanceof Fragment)
                mActivity = ((Fragment) context).getActivity();
            if (mActivity == null)
                return;
            FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            String tagName = context.getClass().getSimpleName();
            View child = parent.findViewById(R.id.loading);
            if (child == null) {
                LinearLayout ll_loading_parent = new LinearLayout(mActivity);
                ll_loading_parent.setGravity(Gravity.CENTER);
                ll_loading_parent.setTag(R.id.loading, tagName);
                ll_loading_parent.setId(R.id.loading);
                ll_loading_parent.setClickable(true);//获得焦点

                LinearLayout ll_loading_view = (LinearLayout) mActivity.getLayoutInflater().inflate(R.layout.display_scaning, null, false);
                ImageView iv_loading = (ImageView) ll_loading_view.findViewById(R.id.iv_loading);
                ll_loading_parent.addView(ll_loading_view);
                parent.addView(ll_loading_parent);

                /**
                 * 选择动画
                 */
                RotateAnimation rotateAnimation = new RotateAnimation(0f, 360f, RotateAnimation.RELATIVE_TO_SELF, 0.5f,
                        RotateAnimation.RELATIVE_TO_SELF, 0.5f);
//                rotateAnimation.setInterpolator(new LinearInterpolator());
                rotateAnimation.setRepeatCount(-1);
                rotateAnimation.setFillAfter(true);
                rotateAnimation.setDuration(1000L);
                iv_loading.startAnimation(rotateAnimation);

                //动画显示图片下标
//                int randomIndex=(int)(Math.random()*loadingAnimRess.length);

                //启动场景动画
//                SceneAnimation sceneAnimation=new SceneAnimation(iv_loading,loadingAnimRess[randomIndex],30);

            } else {
                child.setTag(R.id.loading, tagName);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /** 隐藏扫描动画 */
    public static void hideScaning(Object context) {
        if (context == null)
            return;
        try {
            Activity mActivity = null;
            if (context instanceof Activity)
                mActivity = (Activity) context;
            if (context instanceof Fragment)
                mActivity = ((Fragment) context).getActivity();
            if (mActivity == null)
                return;
            FrameLayout parent = (FrameLayout) mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
            View child = parent.findViewById(R.id.loading);
            if (child != null) {
                String tagName = (String) child.getTag(R.id.loading);
                if (tagName.equals(context.getClass().getSimpleName()))//只有当前开启动画的界面才能关闭界面
                    parent.removeView(child);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Dialog showDialog(Context context, View view, int location) {
        //设置要显示的view
        Dialog dialog = new Dialog(context, R.style.dialog);
        dialog.setContentView(view);
        Window window = dialog.getWindow();
        //设置弹出窗口大小
        window.setLayout(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        //设置显示位置
        window.setGravity(location);
        //设置动画效果
        window.setWindowAnimations(R.style.AnimBottom);
        dialog.show();
        return dialog;
    }
}
